﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mortgage.DAL.Entity;
using Mortgage.DAL;
namespace Mortgage.Srv
{
    public interface IReportSrv
    {
        List<vwMortgageInfo> GetMortgageByStatus(DateTime dteStar, DateTime dteEnd, int ageId, int? statusId);
        List<vwBillTransactionInfo> GetTransaction(DateTime dteStar, DateTime dteEnd, int ageId);
    }
    class ReportSrv : IReportSrv
    {
        private MortgageDataContext dataContext;

        public ReportSrv()
        {
            dataContext = new MortgageDataContext();

        }


        public List<vwMortgageInfo> GetMortgageByStatus(DateTime dteStar, DateTime dteEnd, int ageId, int? statusId)
        {
            List<vwMortgageInfo> result = (from r in dataContext.vwMortgageInfos
                                           where r.Age_ID == ageId
                                           && (r.MorDate >= dteStar && r.MorDate <= dteEnd)
                                           && (statusId == null || r.Status == statusId.GetValueOrDefault())
                                           select r).ToList();
            return result;
        }

        public List<vwBillTransactionInfo> GetTransaction(DateTime dteStar, DateTime dteEnd, int ageId )
        {

            List<vwBillTransactionInfo> result = (from r in dataContext.vwBillTransactionInfos
                                                  where r.Age_ID == ageId
                                                  && (r.MorDate >= dteStar && r.MorDate <= dteEnd)
                                                  select r).ToList();
            return result;

        }
    }
}
